package net.jielan188.hd.controller.mq;

import net.jielan188.hd.service.queue.QueueSender;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;

/**
 * 消息控制器
 * Created by hgg on 2017-01-24.
 */
@Controller
@RequestMapping(value = "/send")
public class ActiveMQAct {

    @Autowired
    private QueueSender queueSender;

    /**
     * 跳转到发送消息页面
     * @return
     */
    @RequestMapping(value = "/to_queue")
    public String to_send(){

        return "queue/send.html";
    }
    /**
     * 发送消息到队列
     * @param message
     * @return String
     */
    @RequestMapping("/queue")
    @ResponseBody
    public String queueSender( @RequestParam("message")String message ){
        String opt="";
        try {
            queueSender.send( "myActiveMQ", message );
            opt="suc";
        } catch ( Exception e ) {
            opt = e.getCause().toString();
        }
        return opt;
    }
}
